import { reqCategoryList, reqGetBannerList, reqGetFloorList } from "@/api"

// home模块的小仓库
const state = {
    categoryList: [],
    bannerList: [],
    floorList: []
}
const actions = {
    //通过api里面的接口函数调用，向服务器发请求，获取数据
    async categoryList({ commit }) {
        let result = await reqCategoryList()
        // console.log(result);
        if (result.code === 200) {
            commit('CATEGORYLIST', result.data)
        }
    },
    //获取轮播图数据
    async getBannerList({ commit }) {
        let result = await reqGetBannerList()
        // console.log(result);
        if (result.code === 200) {
            commit('GETBANNERLIST', result.data)
        }
    },
    //获取家电数据
    async getFloorList({ commit }) {
        let result = await reqGetFloorList()
        // console.log(result);
        // console.log(result.date);
        if (result.code === 200) {
            commit('GETFLOORLIST', result.date)
        }
    }
}
const mutations = {
    //列表
    CATEGORYLIST(state, value) {
        state.categoryList = value
    },
    //轮播图
    GETBANNERLIST(state, value) {
        state.bannerList = value
    },
    //家电
    GETFLOORLIST(state, value) {
        state.floorList = value
        // console.log(state.floorList);
    }
}
const getters = {
}
export default {
    state,
    actions,
    mutations,
    getters
}